#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
@IDE     ：PyCharm 
@Author  ：kiway
@Date    ：2024/9/18 22:18 
"""

import pandas as pd
import requests
from ..config import config


def get_future_symbol_ls():
    if config.sandbox_mode:
        res = requests.get(url="https://testnet.binancefuture.com/fapi/v1/exchangeInfo")

    else:
        res = requests.get(url="https://fapi.binance.com/fapi/v1/exchangeInfo")

    data = res.json()
    if "code" in data:
        raise ValueError("future symbol get nothing")

    df = pd.json_normalize(data["symbols"])
    df = df.query("contractType == 'PERPETUAL' and quoteAsset == 'USDT' and status == 'TRADING'")

    future_symbol_ls = [x + "/USDT:USDT" for x in df["baseAsset"].tolist()]

    return future_symbol_ls


def get_spot_symbol_ls():
    if config.sandbox_mode:
        res = requests.get(url="https://testnet.binance.vision/api/v3/exchangeInfo")

    else:
        res = requests.get(url="https://api.binance.com/api/v3/exchangeInfo")

    data = res.json()
    if "code" in data:
        raise ValueError("spot symbol get nothing")
    df = pd.json_normalize(data["symbols"])
    df = df.query("isSpotTradingAllowed == True and quoteAsset == 'USDT' and status == 'TRADING' ")
    spot_symbol_ls = [x + "/USDT" for x in df["baseAsset"].tolist()]
    return spot_symbol_ls
